// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-07-16

package src

import "context"

type (
	// Job
	// is a required handler of a job, it's called by worker. If an error is
	// returned then call JobFailed.OnFailed() otherwise JobSucceed.OnSucceed()
	// called.
	//
	// Called sequence:
	//
	//   1. OnBefore
	//   2. Do
	//   3. OnFailed / OnSucceed
	//   4. OnFinish
	//
	// Code:
	//
	//   func (o *YourJob) OnRun(ctx context.Context) (err error){
	//       // ...
	//       return
	//   }
	Job interface {
		OnRun(ctx context.Context) (err error)
	}

	// JobBefore
	// is an optional handler of a job, it's called by worker. If an error
	// returned then quit other handlers otherwise Job.OnRun() called.
	//
	//   func (o *YourJob) OnBefore(ctx context.Context) (err error){
	//       // ...
	//       return
	//   }
	JobBefore interface {
		OnBefore(ctx context.Context) (err error)
	}

	// JobFailed
	// is an optional handler of a job, it's called by worker.
	//
	//   func (o *YourJob) OnFailed(ctx context.Context){
	//       // ...
	//   }
	JobFailed interface {
		OnFailed(ctx context.Context, err error)
	}

	// JobFinish
	// is an optional handler of a job, it's called by worker.
	//
	//   func (o *YourJob) OnFinish(ctx context.Context){
	//       // ...
	//   }
	JobFinish interface {
		OnFinish(ctx context.Context)
	}

	// JobSucceed
	// is an optional handler of a job, it's called by worker.
	//
	//   func (o *YourJob) OnSucceed(ctx context.Context){
	//       // ...
	//   }
	JobSucceed interface {
		OnSucceed(ctx context.Context)
	}
)
